package com.machine.filling.db;

import android.content.Context;


import com.machine.filling.db.greendao.DaoMaster;
import com.machine.filling.db.greendao.DaoSession;

import org.greenrobot.greendao.database.Database;

import java.io.File;

/**
 * 作者: SageTripp on
 * 时间: 2017/7/17
 * <p>
 * 描述:数据库操作类
 */

public class DBUtils {
    
    public static DaoSession daoSession;
    public static DaoMaster daomaster;

    /**
     * 初始化数据库
     *
     * @param context 上下文对象
     * @param path    路径
     * @param name    名称
     */
    public static void init(Context context, String path, String name) {
        File dir = new File(path);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        File dbFile = new File(dir, name);
        UpgradeHelper db2 = new UpgradeHelper(context, dbFile.getPath(), null);//建库
        daomaster = new DaoMaster(db2.getWritableDatabase());
        daoSession = daomaster.newSession();
    }
}
